package com.fjsaas.quartz;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.ApplicationContext;

import com.fjsaas.flyway.command.MysqlBackupCommand;
import com.fjsaas.web.constants.Constants;

public class MysqlTask implements Job {

	@Override
	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		JobDataMap dataMap = context.getMergedJobDataMap();
		TaskDetail taskDetail = (TaskDetail) dataMap.get(Constants.JOB_KEY);
		ApplicationContext applicationContext = (ApplicationContext) taskDetail.getMap().get(Constants.APPLICATION_CONTEXT);
		MysqlBackupCommand mysqlBackupCommand = applicationContext.getBean(MysqlBackupCommand.class);
		mysqlBackupCommand.execute();
	}

}
